const ADD_PAGE_POPUP_ACTIVE_NUM = 'ADD_PAGE_POPUP_ACTIVE_NUM'
const DEL_PAGE_POPUP_ACTIVE_NUM = 'DEL_PAGE_POPUP_ACTIVE_NUM'
const CLEAR_PAGE_POPUP_ACTIVE_NUM = 'CLEAR_PAGE_POPUP_ACTIVE_NUM'

export default {
	state: {
		pagePopupOpenList: []
	},
	getters: {
		pagePopupActive: state => state.pagePopupOpenList.length > 0
	},
	actions: {
		AddPagePopupActiveNum ({ commit }, uid) {
			commit(ADD_PAGE_POPUP_ACTIVE_NUM, uid)
		},
		DelPagePopupActiveNum ({ commit }, uid) {
			commit(DEL_PAGE_POPUP_ACTIVE_NUM, uid)
		},
		ClearPagePopupActiveNum ({ commit }) {
			commit(CLEAR_PAGE_POPUP_ACTIVE_NUM)
		}
	},
	mutations: {
		[ADD_PAGE_POPUP_ACTIVE_NUM] (state, uid) {
			if (state.pagePopupOpenList.some(v => v === uid)) {
				return
			}
			state.pagePopupOpenList.push(uid)
		},
		[DEL_PAGE_POPUP_ACTIVE_NUM] (state, uid) {
			const index = state.pagePopupOpenList.indexOf(uid)
			if (index >= 0) {
				state.pagePopupOpenList.splice(index, 1)
			}
		},
		[CLEAR_PAGE_POPUP_ACTIVE_NUM] (state) {
			state.pagePopupOpenList = []
		}
	}
}
